<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="联盟ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="allianceId">
              <j-search-select-tag v-model="model.allianceId" dict="ht_alliance,enterprise_name,id"  />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="账户类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="accountType">
              <j-dict-select-tag type="list" v-model="model.accountType" dictCode="account_type" placeholder="请选择账户类型" />
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="24">
            <a-form-model-item label="注册渠道(0-PC，1-公众号，2-后台）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="channel">
              <j-dict-select-tag type="list" v-model="model.channel" dictCode="sign_up_channel" placeholder="请选择注册渠道(0-PC，1-公众号，2-后台）" />
            </a-form-model-item>
          </a-col> -->
          <a-col :span="24">
            <a-form-model-item label="部门ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="departId">
              <j-search-select-tag v-model="model.departId" dict="ht_alliance_depart,name,id"  />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="手机号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="phoneNumber">
              <a-input v-model="model.phoneNumber" placeholder="请输入手机号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="用户名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="username">
              <a-input v-model="model.username" placeholder="请输入用户名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="姓名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="realName">
              <a-input v-model="model.realName" placeholder="请输入姓名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="昵称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="nickname">
              <a-input v-model="model.nickname" placeholder="请输入昵称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="24">
            <a-form-model-item label="密码(必须包含大小写字母和数字的组合，可以使用特殊字符(~!@#$%^&*)，长度在8-32之间)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="password">
              <a-input v-model="model.password" placeholder="请输入密码(必须包含大小写字母和数字的组合，可以使用特殊字符(~!@#$%^&*)，长度在8-32之间)"  ></a-input>
            </a-form-model-item>
          </a-col> -->
          <a-col :span="24">
            <a-form-model-item label="引理摘要" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="lemmaSummary">
              <a-textarea v-model="model.lemmaSummary" rows="4" placeholder="请输入引理摘要" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="简介" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="introduction">
              <j-editor v-model="model.introduction" />
            </a-form-model-item>
          </a-col>
   
          <a-col :span="24">
            <a-form-model-item label="职位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="position">
              <a-input v-model="model.position" placeholder="请输入职位"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="头像" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="avatar">
              <j-image-upload isMultiple  v-model="model.avatar" ></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="资质证件" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="certificateAttachment">
              <j-upload v-model="model.certificateAttachment"   ></j-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="性别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="gender">
              <j-dict-select-tag type="list" v-model="model.gender" dictCode="gender" placeholder="请选择性别" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="邮箱" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="email">
              <a-input v-model="model.email" placeholder="请输入邮箱"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="生日" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="birthday">
              <j-date placeholder="请选择生日" v-model="model.birthday"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="workNumber">
              <a-input v-model="model.workNumber" placeholder="请输入工号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="审核人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="auditUsername">
              <a-input v-model="model.auditUsername" placeholder="请输入审核人"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="状态：0-未审核 1-审核中 2-已通过 3-已驳回" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="auditStatus">
              <j-dict-select-tag type="list" v-model="model.auditStatus" dictCode="audit_status" placeholder="请选择状态：0-未审核 1-审核中 2-已通过 3-已驳回" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="是否冻结" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isLocked">
              <j-dict-select-tag type="list" v-model="model.isLocked" dictCode="is_locked" placeholder="请选择是否冻结" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'HTAllianceSecretaryForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
            accountType:9,
            gender:0,
            auditStatus:0,
            isLocked:0,
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           allianceId: [
              { required: true, message: '请输入联盟ID!'},
           ],
           accountType: [
              { required: true, message: '请输入账户类型!'},
           ],
          //  channel: [
          //     { required: true, message: '请输入注册渠道(0-PC，1-公众号，2-后台）!'},
          //  ],
           departId: [
              { required: true, message: '请输入部门ID!'},
           ],
           phoneNumber: [
              { required: true, message: '请输入手机号!'},
              { pattern: /^1[3456789]\d{9}$/, message: '请输入正确的手机号码!'},
           ],
           username: [
              { required: true, message: '请输入用户名!'},
           ],
           realName: [
              { required: true, message: '请输入姓名!'},
           ],
          //  password: [
          //     { required: true, message: '请输入密码(必须包含大小写字母和数字的组合，可以使用特殊字符(~!@#$%^&*)，长度在8-32之间)!'},
          //  ],
           lemmaSummary: [
              { required: true, message: '请输入引理摘要!'},
           ],
           introduction: [
              { required: true, message: '请输入简介!'},
           ],
           position: [
              { required: true, message: '请输入职位!'},
           ],
           avatar: [
              { required: true, message: '请输入头像!'},
           ],
           certificateAttachment: [
              { required: true, message: '请输入资质证件!'},
           ],
           gender: [
              { required: true, message: '请输入性别!'},
           ],
           email: [
              { required: false},
              { pattern: /^([\w]+\.*)([\w]+)@[\w]+\.\w{3}(\.\w{2}|)$/, message: '请输入正确的电子邮件!'},
           ],
           auditStatus: [
              { required: true, message: '请输入状态：0-未审核 1-审核中 2-已通过 3-已驳回!'},
           ],
           isLocked: [
              { required: true, message: '请输入是否冻结!'},
           ],
        },
        url: {
          add: "/account/hTAllianceSecretary/add",
          edit: "/account/hTAllianceSecretary/edit",
          queryById: "/account/hTAllianceSecretary/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>